import { ObjectType, Field, Int } from '@nestjs/graphql';
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { CommonSchema } from 'src/common/mongodb/commonSchema';
import { Menu } from 'src/system/menu/entities/menu.entity';

@ObjectType({ description: '后台管理权限数据' })
@Schema({ collection: 'PowerData' })
export class Power extends CommonSchema {
  @Field(() => String)
  @Prop()
  name: string;

  @Field(() => String)
  @Prop()
  code: string;

  @Field(() => String, { nullable: true })
  @Prop()
  url: string;

  @Field(() => Menu, { nullable: true })
  @Prop({ type: String, ref: 'Menu' })
  menu: number;

  @Field(() => Int, { nullable: true })
  menuId: number;

  @Field(() => [String], { nullable: true })
  @Prop()
  operation: [string];

  @Field(() => String, { nullable: true })
  explain: string;
}

export type PowerDocument = Power & Document;
export const PowerSchema = SchemaFactory.createForClass(Power);
